<template>
	<view>
		<view class="smart-page-head">
			<view class="smart-page-head-title">checkbox 复选框</view>
		</view>
		<view class="smart-padding-wrap">

			<view class="item">
				<checkbox checked="true"></checkbox>
				选中
				<checkbox></checkbox>
				未选中
			</view>

		<checkbox-group>
			<label style="background-color: #8A6DE9;">
			<checkbox value="cb1" checked="true" color="#8A6DE9" style="transform: scale(0.7);" />选中
			</label>
			<label>
			<checkbox value="cb" style="transform: scale(0.7);" />未选中
			</label>
		</checkbox-group>

			<view class="item">
				推荐展示样式：
				<checkbox-group @change="checkboxChange">
					<label class="list" v-for="(item, index) in items" :key="index">
						<view>
							<checkbox :value="item.value" :checked="item.checked"></checkbox>
							{{ item.name }}
						</view>
					</label>
				</checkbox-group>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				items: [
					{ value: 'usa', name: '美国', checked: false },
					{ value: 'china', name: '中国', checked: false },
					{ value: 'brazil', name: '巴西', checked: false },
					{ value: 'japan', name: '日本', checked: false },
					{ value: 'uk', name: '英国', checked: false },
					{ value: 'france', name: '法国', checked: false }
				]
			};
		},
		methods: {
			checkboxChange(e) {
				const values = e.detail.value;
				this.items.forEach(item => {
					item.checked = values.includes(item.value);
				});
				console.log('当前选中的值：', values);
				this.items.forEach((item, index) => {
					console.log(`i:${index}---${item.name}, index:${values.indexOf(item.value)}, isCheck: ${item.checked}`);
				});
			}
		}
	};
</script>

<style>

	.item {
		margin-bottom: 15px;
	}

	.list {
		display: block;
		margin-bottom: 8px;
	}
	.list view {
		display: flex;
		align-items: center;
		background-color: #F0AD4E; 
		padding: 6px 8px;
		border-radius: 4px;
	}
	.list checkbox {
		margin-right: 6px; 
	}
</style>